/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.Facturacion;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author dianacha
 */
public class ModeloTablaFact extends AbstractTableModel{

    final String[] columnNames;
    final ArrayList<Object[]> data;
    
    public ModeloTablaFact(ArrayList<String> colNames){
        int size = colNames.size();
        
        columnNames = new String[size];
        for(int i=0;i<size;i++){
            columnNames[i]=colNames.get(i);
        }
        data = new ArrayList<>();
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }
    
    @Override
    public String getColumnName(int j) {
        return columnNames[j];
    }
    
    @Override
    public boolean isCellEditable(int row, int col) {
        /*boolean editable;
        
        if((col==0)||(col==3))
            editable=true;
        else
            editable=false;*/
        
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return (data.get(rowIndex))[columnIndex];
    }
    
    @Override
    public void setValueAt(Object value, int row, int col) {
        data.get(row)[col]=value;
        fireTableCellUpdated(row, col);
    }
    
    public void addRow(Object[] newRow){
        data.add(newRow);
        fireTableDataChanged();
    }
    
    public void clearRows(){
        data.clear();
        fireTableDataChanged();
    }
}
